#include <iostream>
#include <algorithm>

using namespace std;

const int N = 8010;

int n, m;
struct node{
	int x, y, z;
}a[N];

int fa[310], ans;

bool cmp(node& x, node& y)
{
	return x.z < y.z;
} 

int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int kruskal()
{
	sort(a + 1, a + 1 + m, cmp);
	int cnt = 0;
	for(int i = 1; i <= m; i++)
	{
		int x = a[i].x, y = a[i].y, z = a[i].z;
		int fx = find(x), fy = find(y);
		if(fx != fy)
		{
			cnt++;
			ans = max(ans, z);
			fa[fx] = fy;
		}
	}
	return cnt;
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].z;
	}
	
	for(int i = 1; i <= n; i++) fa[i] = i;
	
	int ret = kruskal();
	cout << ret << " " << ans << endl;
	return 0;
}
